package club.monkeywood.repository;

import club.monkeywood.dataobject.Production;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface ProductionInfoRepository extends JpaRepository<Production, Integer> {
    List<Production> findByName(String name);
    List<Production> findByIdIn(List<Integer> ids);
    Production findByCategoryId(Integer id);
    List<Production> findByCategoryIdIn(List<Integer> ids);

    @Query(value="select a.*, b.name categoryName " +
            "from production_info a, production_category b " +
            "where a.category_id=b.id ", nativeQuery = true)
    @Modifying
    List<Production> queryCategoryProductions();

    List<Production> findByStatus(Integer status);
    Page<Production> findByStatus(Integer status, Pageable pageable);
}
